<?php


/**
 * @category   Ahs
 * @package    Ahs_Auth
 * @subpackage Adapter
 * @author Thibaut Cromphaut, Gaïtano Boeraeve, Mathias Helin, Dimitry Dierickx
 * @copyright  Copyright (c) 2011 Artevelde University College Ghent 
 */

class Ahs_Auth_Adapter_DbTable extends Zend_Auth_Adapter_DbTable
{

    public function __construct()
    {
        $dbAdapter = Zend_Db_Table::getDefaultAdapter();
        parent::__construct($dbAdapter);
        
        $this->setTableName('vw_users')
            ->setIdentityColumn('user_has_email')
            ->setCredentialColumn('user_password')
            ->setCredentialTreatment('? AND (user_activedate IS NULL OR user_activedate < NOW())')
            ->setCredentialTreatment('? AND user_deleteddate IS NULL');
    }

    /**
     * authenticate()
     * 
     * @return Zend_Auth_Result
     */
    public function authenticate()
    {
        $authCode   = parent::authenticate()->getCode();
        $identity  = $this->getResultRowObject();
        return new Zend_Auth_Result($authCode, $identity);
    }    
    
    /**
     * setCredential()
     * 
     * @param string $credential
     * @return Ahs_Auth_Adapter_DbTable
     */
    public function setCredential($credential)
    {
        return parent::setCredential( Ahs_Utility::hash($credential) );
    }
    
    /**
     * setIdentity()
     * 
     * @param string $value
     * @return Ahs_Auth_Adapter_DbTable
     */
    public function setIdentity($value)
    {
        return parent::setIdentity($value);
    }
    
}

?>
